package com.boarsoft.boar.config.var.action;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.boarsoft.bean.ReplyInfo;
import com.boarsoft.boar.config.var.ConfigVarAppBiz;
import com.boarsoft.boar.entity.AppInfo;
import com.boarsoft.common.Authorized;
import com.boarsoft.common.dao.PagedResult;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

@Component
@RestController
@RequestMapping("/var/app")
public class ConfigVarAppAction {
	@Autowired
	private ConfigVarAppBiz configVarAppBiz;

	@JsonIgnoreProperties({ "insts", "libs", "files" })
	@RequestMapping("/list.do")
	@Authorized(code = "config.var.app.list")
	public ReplyInfo<Object> list(String varId, String key, String orderBy, int pageNo, int pageSize) {
		PagedResult<AppInfo> pr = configVarAppBiz.list(varId, key, orderBy, pageNo, pageSize);
		return new ReplyInfo<Object>(true, pr);
	}

	@RequestMapping("/toggle.do")
	@Authorized(code = "config.var.app.toggle")
	public ReplyInfo<Object> toggle(String key, String varId, short status) {
		String[] fa = key.split(",");
		configVarAppBiz.toggle(varId, fa, status == 1);
		return ReplyInfo.SUCCESS;
	}
}